package com.gitee.huxing.framework.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;

/**
 * @Description: redis消息发布
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.framework.redis
 * @ClassName: RedisMessagePublisher
 * @Author: huxing
 * @DateTime: 2021-10-26 下午4:14
 */
public class RedisMessagePublisher implements MessagePublisher{

    private RedisTemplate<String, Object> redisTemplate;

    private ChannelTopic topic;

    public RedisMessagePublisher(RedisTemplate<String, Object> redisTemplate, ChannelTopic topic) {
        this.redisTemplate = redisTemplate;
        this.topic = topic;
    }

    @Override
    public void publish(String message) {
        redisTemplate.convertAndSend(topic.getTopic(), message);
    }
}
